package com.xunjing.log.sharding;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xunjing.log.domain.IcPayLog;
import com.xunjing.log.service.IIcPayLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.time.LocalDateTime;


/**
 * @Author ZYT
 * @Date 2024-03-26 14:27
 * @Version 1.0
 * @Describe 项目启动后，优先执行（这里可以不用）
 */
@Slf4j
@Order(value = 1) // 数字越小，越先执行
@Component
public class ShardingTablesLoadRunner implements CommandLineRunner {

    @Resource
    private IIcPayLogService icPayLogService;
    @Override
    public void run(String... args) {
        // 读取已有分表，进行缓存
        LambdaQueryWrapper<IcPayLog> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(IcPayLog::getCreateTime, LocalDateTime.now()).last("limit 1");
        icPayLogService.list();

        log.info(">>>>>>>>>> 【ShardingTablesLoadRunner】缓存已有分表成功 <<<<<<<<<<");

    }
}

